﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Config;
using AspNetCs.Common;

public partial class Master_Admin_SiteConfig : Admin_BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if (!IsPostBack)
            ConfigTableDataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        SiteConfigInfo model = SiteConfig.GetConfig();
        //EmailConfigInfo Emailmodel = EmailConfigs.GetConfig();
        //if (Emailmodel == null) return;
        if (model == null)
            return;
        try
        {
            //Emailmodel.Smtp = StringHelper.ConfigRepalce(Txt_mailServer.Text.Trim());
            //Emailmodel.MailName = StringHelper.ConfigRepalce(Txt_MailUser.Text.Trim()); ;
            //Emailmodel.MailPwd = StringHelper.ConfigRepalce(Txt_MailPwd.Text.Trim()); ;
            //Emailmodel.SmtpDomain = StringHelper.ConfigRepalce(Txt_Maildomain.Text.Trim()); ;

            model.SiteName = StringHelper.ConfigRepalce(SiteName.Text.Trim());
            model.SiteTitle = StringHelper.ConfigRepalce(SiteTitle.Text.Trim());
            model.SiteUrl = StringHelper.ConfigRepalce(SiteUrl.Text.Trim());
            model.InstallDir = StringHelper.ConfigRepalce(InstallDir.Text.Trim());
            model.AdminDir = StringHelper.ConfigRepalce(MasterDir.Text.Trim());
            model.WebmasterName = StringHelper.ConfigRepalce(MasterName.Text.Trim());
            model.WebmasterEmail = StringHelper.ConfigRepalce(MasterMail.Text.Trim());
            model.QQ = StringHelper.ConfigRepalce(Service_QQ.Text.Trim());
            model.Copyright = StringHelper.ConfigRepalce(Txt_CopyRight.Text.Trim());
            model.Meta_Keywords = StringHelper.ConfigRepalce(Txt_Webkey.Text.Trim());
            model.Meta_Description = StringHelper.ConfigRepalce(Txt_WebDes.Text.Trim());
            model.ArticleCheck = StringHelper.isNumber_int(ArticleCheck.SelectedValue);
            model.GuestCheck = StringHelper.isNumber_int(GuestCheck.SelectedValue);
            model.IsUp = StringHelper.isNumber_int(IsUp.SelectedValue);
            model.IsLinkUrl = StringHelper.isNumber_int(IsLink.SelectedValue);
            model.HitsOfHot = StringHelper.isNumber_int(ArticleHot.Text);
            model.SessionTimeOut = StringHelper.isNumber_int(ExpTime.Text);
            model.EnableUserReg = StringHelper.isNumber_int(IsReg.SelectedValue);
            model.EmailCheckReg = StringHelper.isNumber_int(IsRegMail.SelectedValue);
            model.UserRegAdminCheck = StringHelper.isNumber_int(IsAdminCheck.SelectedValue);
            model.UserRegPoint = StringHelper.isNumber_int(Txt_point.Text);
            model.UserRegIntegral = StringHelper.isNumber_int(Txt_Integral.Text);
            model.DayAddIntegral = StringHelper.isNumber_int(Txt_DayAddIntegral.Text);
            model.PointChangeIntegral = StringHelper.isNumber_int(ChangeIntegral.Text);
            model.UserName_RegDisabled = StringHelper.ConfigRepalce(txtUserName_RegDisabled.Text.Trim());
            model.EmailOfRegCheck = StringHelper.ConfigRepalce(txtEmailOfRegCheck.Text.Trim());
            model.UpSize = StringHelper.isNumber_int(Txt_UpSize.Text.Trim());
            model.UpFolder = StringHelper.ConfigRepalce(Txt_UpFolder.Text.Trim());
            model.UpType = StringHelper.ConfigRepalce(Txt_UpType.Text.Trim());
            model.abscondence = StringHelper.isNumber_int(Txt_UpSize.Text.Trim());
            model.Flower = StringHelper.isNumber_int(Flower.Text.Trim());
            model.MusicPoint = StringHelper.isNumber_int(Music.Text.Trim());
            model.Incense = StringHelper.isNumber_int(Incense.Text.Trim());
            model.drinkPoint = StringHelper.isNumber_int(drink.Text.Trim());
            model.tributePoint = StringHelper.isNumber_int(tribute.Text.Trim());
            model.kowtowedPoint = StringHelper.isNumber_int(kowtowed.Text.Trim());
            model.candlePoint = StringHelper.isNumber_int(candle.Text.Trim());
            model.releasePoint = StringHelper.isNumber_int(release.Text.Trim());
            model.OnegravestonePoint = StringHelper.isNumber_int(Onegravestone.Text.Trim());
            model.TwoGravestonePoint = StringHelper.isNumber_int(TwoGravestone.Text.Trim());
            model.lygsNum = StringHelper.isNumber_int(lygs.Text.Trim());
            model.cemeteryPoint = StringHelper.isNumber_int(cemetery.Text.Trim());
            model.onLineLikePoint = StringHelper.isNumber_int(onLineLike.Text.Trim());
            model.onlineTime = StringHelper.isNumber_int(onlineTime.Text.Trim());
            model.IsDns = (IsDns.Checked == true ? 1 : 0);
            model.DnsUrl = StringHelper.ConfigRepalce(DnsUrl.Text.Trim());
            model.ancestralhallPoint = StringHelper.isNumber_int(ancestralhall.Text.Trim());
            model.U_Create_Num = StringHelper.isNumber_int(U_Create_Num.Text.Trim());
            model.HappyPet = StringHelper.isNumber_int(txtHappyPet.Text.Trim());
            model.abscondence = StringHelper.isNumber_int(txtFindFamily.Text.Trim());

            model.Smtp = StringHelper.ConfigRepalce(Txt_mailServer.Text.Trim());
            model.SmtpDomain = StringHelper.ConfigRepalce(Txt_Maildomain.Text.Trim());
            model.MailName = StringHelper.ConfigRepalce(Txt_MailUser.Text.Trim());
            model.MailPwd = StringHelper.ConfigRepalce(Txt_MailPwd.Text.Trim());
            model.Pic_IsCheck = StringHelper.isNumber_int(pic_Ischeck.Text);


            UpdateConfigInfo(model);
            RefreshSystemCache();
            ConfigTableDataBind();
            Response.Write("<script>alert('更新成功!');location.href='Admin_SiteConfig.Aspx';</script>");
            Response.End();
        }
        catch(Exception ex)
        {

            Response.Write("<script>alert('配置出错了,请注意输入参数!');history.back()</script>");
            //Response.Write(ex.Message);
            Response.End();

        }



    }
    /// <summary>
    /// 更新设置信息
    /// </summary>
    /// <param name="model"></param>
    protected void UpdateConfigInfo(SiteConfigInfo model)
    {
        if (model != null)
        {
            SiteConfig.Serialiaze(model, SiteConfigFileManager.ConfigFilePath);
        }
    }

    /// <summary>
    /// 填充控件
    /// </summary>
    protected void ConfigTableDataBind()
    {
        SiteConfigInfo model = SiteConfig.GetConfig();
        SiteName.Text = StringHelper.ConfigRepalce_Re(model.SiteName);
        SiteTitle.Text = StringHelper.ConfigRepalce_Re(model.SiteTitle);
        SiteUrl.Text = StringHelper.ConfigRepalce_Re(model.SiteUrl);
        InstallDir.Text = StringHelper.ConfigRepalce_Re(model.InstallDir);
        MasterDir.Text = StringHelper.ConfigRepalce_Re(model.AdminDir);
        MasterName.Text = StringHelper.ConfigRepalce_Re(model.WebmasterName);
        MasterMail.Text = StringHelper.ConfigRepalce_Re(model.WebmasterEmail);
        Service_QQ.Text = StringHelper.ConfigRepalce_Re(model.QQ).Trim();
        Txt_CopyRight.Text = StringHelper.ConfigRepalce_Re(model.Copyright);
        Txt_Webkey.Text = StringHelper.ConfigRepalce_Re(model.Meta_Keywords);
        Txt_WebDes.Text = StringHelper.ConfigRepalce_Re(model.Meta_Description);
        ArticleCheck.SelectedValue = model.ArticleCheck.ToString();
        pic_Ischeck.Text = model.Pic_IsCheck.ToString();
        GuestCheck.SelectedValue = model.GuestCheck.ToString();
        IsUp.SelectedValue = model.IsUp.ToString();
        IsLink.SelectedValue = model.IsLinkUrl.ToString();
        ArticleHot.Text = model.HitsOfHot.ToString();
        ExpTime.Text = model.SessionTimeOut.ToString();
        IsReg.SelectedValue = model.EnableUserReg.ToString();
        IsRegMail.SelectedValue = model.EmailCheckReg.ToString();
        IsAdminCheck.SelectedValue = model.UserRegAdminCheck.ToString();
        Txt_point.Text = model.UserRegPoint.ToString();
        Txt_Integral.Text = model.UserRegIntegral.ToString();
        Txt_DayAddIntegral.Text = model.DayAddIntegral.ToString();
        ChangeIntegral.Text = model.PointChangeIntegral.ToString();
        txtUserName_RegDisabled.Text = StringHelper.ConfigRepalce_Re(model.UserName_RegDisabled.ToString());
        txtEmailOfRegCheck.Text = StringHelper.ConfigRepalce_Re(model.EmailOfRegCheck.ToString());
        Txt_UpSize.Text = model.UpSize.ToString();
        Txt_UpFolder.Text = StringHelper.ConfigRepalce_Re(model.UpFolder.ToString());
        Txt_UpType.Text = StringHelper.ConfigRepalce_Re(model.UpType.ToString());
        Flower.Text = model.Flower.ToString();
        Music.Text = model.MusicPoint.ToString();
        Incense.Text = model.Incense.ToString();
        drink.Text = model.drinkPoint.ToString();
        tribute.Text = model.tributePoint.ToString();
        kowtowed.Text = model.kowtowedPoint.ToString();
        candle.Text = model.candlePoint.ToString();
        release.Text = model.releasePoint.ToString();
        Onegravestone.Text = model.OnegravestonePoint.ToString();
        TwoGravestone.Text = model.TwoGravestonePoint.ToString();
        lygs.Text = model.lygsNum.ToString();
        cemetery.Text = model.cemeteryPoint.ToString();
        onLineLike.Text = model.onLineLikePoint.ToString();
        onlineTime.Text = model.onlineTime.ToString();
        txtHappyPet.Text = model.HappyPet.ToString();
        txtFindFamily.Text = model.abscondence.ToString();
        if (model.IsDns == 1)
        {
            IsDns.Checked = true;
        }
        else
        {
            IsDns.Checked = false;
        }
        DnsUrl.Text = model.DnsUrl.ToString();
        ancestralhall.Text = model.ancestralhallPoint.ToString();
        U_Create_Num.Text = model.U_Create_Num.ToString();

        Txt_mailServer.Text = StringHelper.ConfigRepalce_Re(model.Smtp.ToString()); ;

        Txt_Maildomain.Text = StringHelper.ConfigRepalce_Re(model.SmtpDomain.ToString());
        Txt_MailUser.Text = StringHelper.ConfigRepalce_Re(model.MailName.ToString());

        Txt_MailPwd.Text = StringHelper.ConfigRepalce_Re(model.MailPwd.ToString());



    }
}
